package com.zxd;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class HbaseDemo {
    private Configuration config;
    private Connection conn;
    private Admin admin;

    public void init() throws IOException {
        config = HBaseConfiguration.create();
        config.set(HConstants.HBASE_DIR, "hdfs://node1:8020/hbase");
        config.set(HConstants.ZOOKEEPER_QUORUM, "node1");
        config.set(HConstants.CLIENT_PORT_STR, "2181");

        conn = ConnectionFactory.createConnection(config);
        admin = conn.getAdmin();
    }

    public void close() throws IOException {
        if (admin != null) {
            admin.close();
        }
        if (conn != null) {
            conn.close();
        }

    }
}
